<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/public.css">
</head>

<body>
    <!-- getImageData  返回 ImageData 对象，该对象为画布上指定的矩形复制像素数据 -->
    <!-- putImageData  把图像数据（从指定的 ImageData 对象）放回画布上 -->

    <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"></canvas>

    <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        ctx.fillStyle = "red";
        ctx.fillRect(10, 10, 50, 50);
        function copy() {
            var imgData = ctx.getImageData(10, 10, 50, 50);
            ctx.putImageData(imgData, 10, 70);
        }
    </script>
</body>

</html>